import os
import shutil
import file_move.delete_path as f
import common.gyblog as log

LOG = log.get_logger()


def copy_cover(path):
    root_dirs = os.listdir(path)
    for dir in root_dirs:
        del_path = path + dir
        d = os.listdir(del_path)[0]
        cover = del_path + '\\' + d
        dis_cover = '\\\\lcnas\\xishu16t2020_1\comic\zz\\' + dir + d[-4:]
        shutil.copy(cover, dis_cover)
    LOG.info('封面复制完成！')
    print('【copy_cover】完成')


def copy_dir():
    src_dirs = os.listdir('\\\\lcnas\\xishu16t2020_1\comic\zz\\')
    for i, src_dir in enumerate(src_dirs):
        src_path = PATH + src_dir[:-4]
        dis_path = '\\\\lcnas\\xishu16t2020_1\comic\zzok\\' + src_dir[:-4]
        try:
            shutil.copytree(src_path, dis_path)
            print('【copy_dir】进度{}/{}'.format(str(i + 1), str(len(src_dirs))))
        except:
            print('【copy_dir】error!,【from】{},【to】{}'.format(src_path, dis_path))
    LOG.info('复制漫画完成：copy num: {}'.format(str(len(src_dirs))))
    print('copy num: {}'.format(str(len(src_dirs))))


if __name__ == '__main__':

    PATH = '\\\\lcnas\\xishu16t2020_1\choosefc2\\'

    f.delete_kongdir(PATH)
    copy_cover(PATH)
    print('挑完了吗：')
    is_ok = input()
    if is_ok == 'y' or is_ok == 'Y':
        copy_dir()
